package com.haste.controller;

import com.haste.pojo.Dept;
import com.haste.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName:DeptController
 * @Description:
 * @Author:Haste
 * @Date:2021/2/1 17:41
 */
@RestController
public class DeptController {
    @Resource
    private DeptService deptService;

    @HystrixCommand(fallbackMethod = "Hystrixget")
    @GetMapping("/dept/get/{deptId}")
    public Dept get(@PathVariable("deptId") Long deptId){
        Dept dept = deptService.queryById(deptId);
        if (dept == null){
            throw new RuntimeException("查询的"+deptId+"id不存在，用户信息无法找到");
        }
        return deptService.queryById(deptId);
    }

    public Dept Hystrixget(@PathVariable("deptId") Long deptId){
        return new Dept()
                .setDeptId(deptId)
                .setDeptName("查询的"+deptId+"不存在，无法找到用户信息")
                .setDbSource("在数据库中没有这个数据");
    }

}
